package com.ufgov.agcfs.baseData.service.util;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;

import com.ufgov.agcfs.baseData.entity.AgcfsSysItem;

public class AgcfsItemUtil {
	//按年度删除
	public void deleteItemByNd(JdbcTemplate jdbcTemplate, String nd) throws Exception{
		String sql = "delete from AGCFS_SYS_ITEM where nd=?";
		String[] param=new String[]{nd};
		int[] type=new int[]{java.sql.Types.VARCHAR};
		jdbcTemplate.update(sql, param, type);
	}

	//插入数据
	public void insertItems(JdbcTemplate jdbcTemplate, List<AgcfsSysItem> list) throws Exception{
		final int count=list.size();
		final List<AgcfsSysItem> list2=list;
		jdbcTemplate.batchUpdate("INSERT INTO AGCFS_SYS_ITEM (ID,ND,REPORT_ITEM_CODE,REPORT_ITEM_NAME,P_ITEM_CODE,REPORT_ITEM_TYPE,BAL_DIR,REMARK) VALUES (?,?,?,?,?,?,?,?)"
				, new BatchPreparedStatementSetter(){
			@Override
			public int getBatchSize() {
				return count;
			}

			@Override
			public void setValues(PreparedStatement ps, int i)
					throws SQLException {
				AgcfsSysItem item=list2.get(i);
				
				ps.setString(1, item.getId());
				ps.setString(2, item.getNd());
				ps.setString(3, item.getReportItemCode());
				ps.setString(4, item.getReportItemName());
				ps.setString(5, item.getPitemCode());
				ps.setString(6, item.getReportItemType());
				ps.setString(7, item.getBalDir());
				ps.setString(8, item.getRemark());
			}
			
		});
	}
}
